package com.ankicoo.practice.coding;

import lombok.SneakyThrows;

public class SyncTest {

    public  static class DataA{
        private  static int a = 0;

        public synchronized static int getA(){
            return a;
        }

        public synchronized static void aPlus(){
            a = a+1;
        }

        public synchronized static void setA(int value){
            a = value;
        }
    }

    static class MyThread extends Thread{
        @Override
        public void run() {
            int A = DataA.getA();
//            sleep(2000);
            System.out.println(A+1);
            DataA.setA(A+1);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        MyThread t1 = new MyThread();
        MyThread t2 = new MyThread();
        t1.start();
        t2.start();

//        Thread.sleep(6000);
        System.out.println(DataA.getA());
    }

}
